/*

Frequency of use: 1 2 3 4 [5] HIGH

Short:
    Factory method creates some object (in this case a string) in a derived 
class, for use in a base class.

Long:
    The factory method pattern is an object-oriented design pattern. Like other 
creational patterns, it deals with the problem of creating objects (products) 
without specifying the exact class of object that will be created. The factory 
method design pattern handles this problem by defining a separate method for 
creating the objects, whose subclasses can then override to specify the derived 
type of product that will be created. More generally, the term factory method is 
often used to refer to any method whose main purpose is creation of objects.

Information sources:
 - http://calumgrant.net/patterns/index.html
 - http://en.wikipedia.org/wiki/Factory_method_pattern
 - http://www.dofactory.com/Patterns/Patterns.aspx
*/

#include <iostream>
#include <string>

class Greeter
{
public:
	virtual ~Greeter() { }
	virtual std::string get_message()=0;
	void greet()
	{
		std::cout << get_message() << std::endl;
	}
};

class HelloWorld : public Greeter
{
public:
	std::string get_message()
	{
		return "Hello world!";
	}
};

void hello_world(Greeter & greeter)
{
	greeter.greet();
}

int main()
{
	HelloWorld greeter;
	hello_world(greeter);
	return 0;
}
